package com.settlement.system.controller;

import com.settlement.system.common.annotation.PreventDuplicateSubmit;
import com.settlement.system.common.result.Result;
import com.settlement.system.model.form.CheckInForm;
import com.settlement.system.model.form.PlatformForm;
import com.settlement.system.service.SysAuditCheckInService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

/**
 * <p>
 * 核销登记表 前端控制器
 * </p>
 *
 * @author huangrensen
 */
@Tag(name = "核销登记表")
@RestController
@RequestMapping("/api/v1/auditCheckIn")
@RequiredArgsConstructor
public class SysAuditCheckInController {
    private final SysAuditCheckInService sysAuditCheckInService;

    @Operation(summary = "保存核销登记表", security = {@SecurityRequirement(name = "Authorization")})
    @PostMapping("save")
    @PreAuthorize("@ss.hasPerm('sys:auditCheckIn:save')")
    @PreventDuplicateSubmit
    public Result<?> saveCheckIn(@RequestBody @Valid CheckInForm checkInForm) {
        boolean result = sysAuditCheckInService.saveCheckIn(checkInForm);
        return Result.judge(result);
    }

    @Operation(summary = "审核核销登记表", security = {@SecurityRequirement(name = "Authorization")})
    @PostMapping("confirm")
    @PreAuthorize("@ss.hasPerm('sys:auditCheckIn:confirm')")
    @PreventDuplicateSubmit
    public Result<?> confirm(@RequestBody @Valid CheckInForm checkInForm) {
        boolean result = sysAuditCheckInService.confirm(checkInForm);
        return Result.judge(result);
    }

    @Operation(summary = "拒绝核销登记表", security = {@SecurityRequirement(name = "Authorization")})
    @PostMapping("reject")
    @PreAuthorize("@ss.hasPerm('sys:auditCheckIn:reject')")
    @PreventDuplicateSubmit
    public Result<?> reject(@RequestBody @Valid CheckInForm checkInForm) {
        boolean result = sysAuditCheckInService.reject(checkInForm);
        return Result.judge(result);
    }

    @Operation(summary = "核销登记历史记录", security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping("/history/{orderNo}")
    public Result<?> list(@PathVariable String orderNo) {
        return Result.success(sysAuditCheckInService.getHistory(orderNo));
    }
}
